﻿using System;
using System.Collections.Generic;

namespace ExpressesClass.Method
{
    public class LambdaQualComparer<T> : IEqualityComparer<T>
    {
        private readonly Func<T, T, bool> _lambdaComparer;
        private readonly Func<T, int> _lambdaHash;
        public LambdaQualComparer(Func<T, T, bool> lambdaComparer) : this(lambdaComparer, EqualityComparer<T>.Default.GetHashCode)
        {
        }
        public LambdaQualComparer(Func<T, T, bool> lambdaComparer, Func<T, int> lambdaHash)
        {
            if (lambdaComparer == null)
            {
                throw new ArgumentNullException("lambdaComparer");
            }
            if (lambdaHash == null)
            {
                throw new ArgumentNullException("lambdaHash");
            }
            _lambdaComparer = lambdaComparer;
            _lambdaHash = lambdaHash;
        }
        public bool Equals(T x, T y)
        {
            return _lambdaComparer(x, y);
        }
        public int GetHashCode(T obj)
        {
            return _lambdaHash(obj);
        }
    }
}
